package com.itheima.mm.wx.controller;

import com.itheima.mm.dto.CommonDTO;
import com.itheima.mm.pojo.Dict;
import com.itheima.mm.utils.LocationUtil;
import com.itheima.mm.vo.CourseVO;
import com.itheima.mm.vo.wx.CommonVO;
import com.itheima.mm.wx.service.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description DictMapper
 * @Author junyi
 * @Date 2024-06-27
 */
@Slf4j
@RestController
@RequestMapping("/common")
public class CommonController {

    @Autowired
    private CommonService commonService;


    /**
     * 查找城市
     * junyi
     * @param commonDTO
     * @return
     */
    @PostMapping("/citys.do")
    public CommonVO citys(@RequestBody CommonDTO commonDTO){

        //根据经纬度获取城市名字
        String cityName = LocationUtil.parseLocation(commonDTO.getLocation());
        //根据城市名获取城市
        Dict city  = commonService.getCityName(cityName);
        //根据标志获取城市列表
        List<Dict> cityList = commonService.getCityList(commonDTO.getFs());

        CommonVO commonVO = new CommonVO();

        commonVO.setCitys(cityList);
        commonVO.setLocation(city);

        return commonVO;
    }

    /**
     * kangwei
     * 查找课程
     * @Date 2024-06-27
     */
    @PostMapping("/courseList.do")
    public List<CourseVO> courseList(){
        List<CourseVO> courseList = commonService.getCourseList();
        return courseList;
    }
}
